package com.hps.demo.service.converter;

import com.hps.demo.dto.StudentDTO;
import com.hps.demo.entity.Student;
import com.hps.demo.service.IClazzService;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author heps
 * @since 2020/11/11 9:35
 */
@Mapper(componentModel = "spring")
public abstract class StudentConverter extends BaseConverter<StudentDTO, Student> {

  protected IClazzService clazzService;

  @Autowired
  public void setClazzService(IClazzService clazzService) {
    this.clazzService = clazzService;
  }

  @Mappings({
      @Mapping(target = "clazz", expression = "java(clazzService.getClazzById(student.getClazzId()))"),
      @Mapping(target = "genderName", expression = "java(com.hps.demo.enums.GenderEnum.getMessage(student.getGender()))")
  })
  @Override
  public abstract StudentDTO toDTO(Student student);
}
